package com.czxy.Servlet;

import cn.itcast.servlet.BaseServlet;
import com.czxy.Service.AdminService;
import com.czxy.Service.DownLoadService;
import com.czxy.domain.Admin;
import com.czxy.domain.DownLoad;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.List;

@WebServlet("/AdminS")
public class AdminServlet extends BaseServlet {
    private AdminService adminService = new AdminService();
    private DownLoadService downLoadService = new DownLoadService();
    //后台登录方法
    public void login() throws IOException {
        Admin admin = toBean(Admin.class);
        Admin login = adminService.login(admin);
        if (login==null){
            //登录失败
            getResponse().getWriter().print("{\"message\":\"用户名或密码错误!请重新输入\",\"flag\":false}");
            return;
        }else{
            //登陆成功
            getRequest().getSession().setAttribute("adminUser",login);
            getResponse().getWriter().print("{\"message\":\"登录成功!\",\"flag\":true}");
            return;
        }
    }

    //查询视频
    public void selectAllVideo() throws ServletException, IOException {
        List<DownLoad> allVideo = downLoadService.findAllVideo02();
        //把视频信息反馈给浏览器页面
        getRequest().setAttribute("VideoList",allVideo);
        getRequest().getRequestDispatcher("/admin/teindex.jsp").forward(getRequest(),getResponse());
    }
}
